/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.gui.security;

import it.polimi.registration.business.security.boundary.InviteManager;
import it.polimi.registration.business.security.boundary.NotificationManager;
import it.polimi.registration.business.security.boundary.SystemNotificationManager;
import it.polimi.registration.business.security.boundary.UserManager;
import it.polimi.registration.business.security.entity.Friend;
import it.polimi.registration.business.security.entity.Invite;
import it.polimi.registration.business.security.entity.SystemNotification;
import java.io.Serializable;
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import java.util.List;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author Stefano
 */
@Named
@ViewScoped
public class NotificationView implements Serializable{
    
    @Inject 
    private InviteManager im;
    
    @Inject 
    private SystemNotificationManager sm;
    
    @Inject 
    private UserManager um;
    
    @Inject 
    private InviteBean ib;
    
    @Inject 
    private NotificationManager nm;
    
    private Invite invite;
    private SystemNotification systemNotification;
    private Friend friendshipNotification;
    

    private List<Invite> inviteList;
    private List<SystemNotification> systemNotificationList;
    private List<Friend> friendshipNotificationList; 
    private boolean thereisanotify;
    
    public List<Invite> getInviteList() {
        inviteList = im.findInvites(um.getLoggedUser());
        return inviteList;
    }
    
    public List<SystemNotification> getSystemNotificationList() {
        systemNotificationList = sm.findNotification(um.getLoggedUser());
        
        return systemNotificationList;
    }
    
    public List<Friend> getFriendNotificationList()
    {
        friendshipNotificationList = nm.findFriendNotification(um.getLoggedUser());
        return friendshipNotificationList;
    }
    
    
    public void accept(Invite invite){
        ib.accept(invite);
    }
    
    public void decline(Invite invite){
        ib.decline(invite);
    }
    
    public Invite getInvite(){
        if (invite == null) {
            invite = new Invite();
        }
        return invite;
    }
    
    public SystemNotification getSystemNotification(){
        if (systemNotification == null) {
            systemNotification = new SystemNotification();
        }
        return systemNotification;
    }
    
    public void ThereIsanotify()
    {
        getFriendNotificationList();
        getSystemNotificationList();
        getInviteList();
        if(inviteList==null && systemNotificationList==null&& friendshipNotificationList==null)
        {
            this.thereisanotify=FALSE;    
        }
        else
        {
            this.thereisanotify=TRUE;
        }
        System.out.println("flag aggiornato a: "+this.thereisanotify);
    }
    public boolean getFlagnotify()
        {
            return this.thereisanotify;
        }
    
}
